//
// Created by yuping.li on 10/17/24.
//

#ifndef DS18B20_GET_TEMPERATURE_TASK_HPP_
#define DS18B20_GET_TEMPERATURE_TASK_HPP_

#include "task.hpp"
#include "ds18b20/ds18b20_driver.hpp"
#include "rte/rte.hpp"

class Ds18b20GetTemperatureTask : public Task {
public:
  Ds18b20GetTemperatureTask() {
    period_ms = 1000U;
  }

  void init_task() override {
    uint8_t ret1 = ds18b20_air.init();
    uint8_t ret2 = ds18b20_heater.init();
    CCLOG(SWEN_INFO, "init %u %u", ret1, ret2);
  }

  void period_task() override {
    Rte::instance().heater_temp = ds18b20_heater.get_temperature();
    Rte::instance().current_temp = ds18b20_air.get_temperature();
//    CCLOG(SWEN_INFO, "temperature %d %d", Rte::instance().heater_temp, Rte::instance().current_temp);
  }

protected:
  Ds18b20Driver ds18b20_air{GPIOC, GPIO_PIN_10};
  Ds18b20Driver ds18b20_heater{GPIOC, GPIO_PIN_11};
};

#endif //DS18B20_GET_TEMPERATURE_TASK_HPP_
